﻿@model WoodAdmin.Models.SysUser
@inject WoodAdmin.Services.SysRoleService _roleService;

    <fieldset class="layui-elem-field layui-field-title">
        <legend>用户编辑</legend>
    </fieldset>
    <form class="layui-form" onsubmit="return false;">
        <input type="hidden" name="ID" value="@(Model.ID>0?Model.ID.ToString():"")" />
        <input type="hidden" name="UserID" value="@(Model.ID>0?Model.ID.ToString():"")" />
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md7">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="NickName" lay-verify="required" placeholder="姓名" autocomplete="off" class="layui-input" value="@(Model.NickName??"")">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md7">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="Name" lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input" value="@(Model.Name??"")">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md7">
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="text" name="Password" lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input" value="@(Model.Password??"")">
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md7">
            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-block">
                    @foreach (var role in _roleService.Queryable())
                    {
                        int count = 0;
                        @foreach (var userRoleId in Model.RoleIds)
                        {
                            if (userRoleId == role.ID)
                            {
                                count++;
                                <input type="checkbox" name="RoleIds" value="@role.ID" title="@role.Name" checked>
                                break;
                            }
                        }
                        if (count == 0)
                        {
                            <input type="checkbox" name="RoleIds" value="@role.ID" title="@role.Name">
                        }
                    }
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formData" onclick="save('/SysUser/AddEdit','/SysUser/Index')">立即提交</button>
            </div>
        </div>
    </form>

